package org.juiceshop.gm;

import java.util.Map;

public class Util {

	private Util() {}

	public static <Type> int findInArray (Type[] array, Type element) {
		for (int i=0; i<array.length; i++) {
			if (array[i].equals(element)) return i;
		}
		return -1;
	}

	@SuppressWarnings("unchecked")
	public static Map<String,Object> asMap(Object obj) {
		return (Map<String,Object>)obj;
	}
	
	public static boolean isEmpty(String s) {
		return s==null || s.length()==0;
	}
	
	public static String join(Iterable<?> objects, Object delimiter) {
		StringBuilder sb = new StringBuilder();
		for (Object obj : objects) {
			if (sb.length()>0) sb.append(delimiter);
			sb.append(obj);
		}
		return sb.toString();
	}

	
}
